//
//  CityDataInitalManager.m
//  GCDTest
//
//  Created by 正合适 on 2017/11/20.
//  Copyright © 2017年 正合适. All rights reserved.
//

#import "CityDataInitalManager.h"
#import <FMDB/FMDB.h>
@implementation CityDataInitalManager
+ (void)loadCityDataWithAsync:(BOOL)async {
    if (async) {
        // 异步
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            [CityDataInitalManager loadDatas];
        });
    } else {
        [CityDataInitalManager loadDatas];
    }
}

+ (void)loadDatas {
    NSString *doc =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES)  lastObject];
    NSString *fileName = [doc stringByAppendingPathComponent:@"shentong_scoring_deu.sqlite"];
    FMDatabase *db = [FMDatabase databaseWithPath:fileName];
    NSString *strResourcesBundle = [[NSBundle mainBundle] pathForResource:@"ZHUIKit.bundle/Resources" ofType:@"bundle"];
    NSString *filePath = [[NSBundle bundleWithPath:strResourcesBundle] pathForResource:@"nationalCityInfo" ofType:@"sql" inDirectory:@"sql"];
    NSError *error;
    NSString *sql = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
    if ([db open]) {
        BOOL result = [db executeStatements:sql];
        if (result) {
            NSLog(@"创建表成功");
        }
    }
}
@end
